package com.dk.service.impl;

import com.dk.mapper.TCategoryMapper;
import com.dk.pojo.TCategory;
import com.dk.pojo.TCategoryExample;
import com.dk.service.CategoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private TCategoryMapper categoryMapper;

    @Override
    public PageInfo<TCategory> getInfo(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TCategory> list = categoryMapper.getInfo();
        PageInfo<TCategory> page = new PageInfo<>(list);
        return page;
    }

    @Override
    public int add(TCategory category) {
        return categoryMapper.insert(category);
    }

    @Override
    public List<TCategory> getInfoByChannnel() {
        return categoryMapper.getInfoByChannnel();
    }

    @Override
    public TCategory toUpdate(Integer catId) {
        return categoryMapper.selectByPrimaryKey(catId);
    }

    @Override
    public int updateChannel(TCategory category) {
        return categoryMapper.updateByPrimaryKeySelective(category);
    }

    @Override
    public int deleteInfoById(Integer catId) {
        return categoryMapper.deleteByPrimaryKey(catId);
    }

    @Override
    public List<TCategory> selectCat() {
        TCategoryExample example = new TCategoryExample();
        List<TCategory> list = categoryMapper.selectByExample(example);
        return list;
    }
}
